package com.cskaoyan.day1.datastructure;

/**
 * @author Common-zhou
 * @since 2023-02-27 16:02
 */
public class NodeDemo {
    public static void main(String[] args) {

        Node<Integer> node7 = new Node<>();
        node7.data = 7;

        Node<Integer> node8 = new Node<>();
        node8.data = 8;
        node8.next = node7;

        Node<Integer> node5 = new Node<>();
        node5.data = 5;
        node5.next = node8;

        Node<Integer> node10 = new Node<>();
        node10.data = 10;
        node10.next = node5;

        // 怎样去遍历呢？ 使用一个指针，从头结点开始，依次往后走
        // 直到遍历完所有数据
        Node<Integer> head = node10;

        //System.out.println(head.data);
        //head = head.next;
        //
        //System.out.println(head.data);
        //head = head.next;
        while (head != null) {
            System.out.println(head.data);
            head = head.next;
        }
        // 如果我想访问第三个元素，不能随机访问，只能挨个访问，直到到达第三个
        // ints[2]

        head = node10;

        int count = 3;
        int currentCount = 1;
        while (currentCount != count) {
            head = head.next;
            currentCount++;
        }

        System.out.println(head.data);


    }
}
